﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.Mvc;
using System.Net.Mail;
namespace QLDAOL.Email
{
   
        public class EMailAddresss
        {

            public static string SendMail1(string subject, string body, string to, bool isHtml, bool isSSL)
            {

                try
                {

                    using (MailMessage mail = new MailMessage())
                    {

                        mail.From = new MailAddress(GetAddress.FormAddress, "daithanh1990");

                        mail.To.Add(to);

                        mail.Subject = subject;

                        mail.Body = body;

                        mail.IsBodyHtml = isHtml;

                        SmtpClient client = new SmtpClient();

                        client.EnableSsl = isSSL;
                        client.Port = 587;
                        client.Credentials = new System.Net.NetworkCredential("daithanh1990@gmail.com", "D@ithanh123");
                        client.Host = "smtp.gmail.com";
                        client.Send(mail);

                    }

                }

                catch (SmtpException ex)
                {
                    string kq = "lỗi rồi";
                    return kq;

                }

                return "Send email successful!";

            }


            public static bool send(string template_path, string email, string pass)
            {
                StreamReader sr = new StreamReader(template_path);

                sr = System.IO.File.OpenText(template_path);

                string content = sr.ReadToEnd();

                content = content.Replace("[Sender]", "daithanh1990@gmail.com");

                content = content.Replace("[Email]", email);

                content = content.Replace("[Pass]", pass);

                content = content.Replace("[DateTime]", DateTime.Now.ToShortDateString());

                try
                {
                    string kq = QLDAOL.Email.EMailAddresss.SendMail1("Liên hệ khách hàng", content, email, true, true);
                    return true;

                }

                catch (Exception ex)
                {

                    return false;

                }
                return true;
            }
        }
    }
